package com.project.dao.sys;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.project.dao.BaseDao;
import com.project.entity.sys.Area;

/**
 * AreaDao
 * @author MG
 *
 */
@Repository
public class AreaDao extends BaseDao<Area>{

	public List<Area> getProvinceList(){
		String hql = "From Area where parentcode is null and status='1' ORDER BY id";
		return super.find(hql);
	}
	
	public List<Area> getChildList(String code){
		String hql = "From Area where parentcode = ? and status='1' ";
		return super.find(hql,code);
	}
	
	public List<Area> getAreaList(String provincecode) {
		String hql = "From Area where provincecode=?  and status= '1' ";
		return super.find(hql, provincecode);
	}
	
	/**
	 * 通过code 找出对应的 省市区名称
	 * @param code
	 * @return 找出对应的 省市区名称
	 */
	public String getAreaNameByCode(String code){
		String sql = "select name from S_AREA where code ='"+code+"'";
		return getCurrentSession().createSQLQuery(sql).uniqueResult().toString();
	}
	
	
}
